package com.gaoqi.springboot_shiro.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 获取bean 工具类
 */
@Configuration
public class ApplicationContextUtils implements ApplicationContextAware {

    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    //根据bean 的名字在工厂中获取指定bean
    public static RedisTemplate getRedisTemplate() {
        return (RedisTemplate) context.getBean("redisTemplate");

    }

    public static Object getBean() {
        return null;
    }
}
